/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-20
 * Time: 13:55
 */
//https://leetcode.cn/problems/search-insert-position/
public class Test {
    public static int searchInsert(int[] arr, int target) {
        int p1=0,p2=arr.length-1,p=(p1+p2)/2;
        while(p1<=p2){
            if(arr[p]==target || (arr[p]>target&& (p-1<0|| (p-1>=0&&arr[p-1]<target))) ){
                return p;
            }
            if(arr[p]<target){
                p1=p+1;
            }
            else{
                p2=p-1;
            }
            p=(p1+p2)/2;
        }
        if(p==arr.length-1){
            p++;
        }
        return p;
    }
    public static void main(String[] args) {
        int[] arr={1,3,5,7,9,11,13};
        System.out.println(searchInsert(arr,10));
    }
}
